//
//  HACChartDataBase.m
//  Pods
//
//  Created by Hotacool on 2017/8/30.
//
//

#import "HACChartData.h"

@implementation HACChartData

- (instancetype)initWithDataSets:(NSArray <HACChartDataSet*>*)dataSets {
    if (self = [super init]) {
        _dataSets = dataSets;
    }
    return self;
}

- (HACChartData *)appendWithData:(HACChartData *)data {
    if (data.dataSets
        &&data.dataSets.count>0) {
        for (HACChartDataSet *item in self.dataSets) {
            HACChartDataSet *appendDataSet = [data dataSetWithLabel:item.label];
            if (appendDataSet) {
                item.values = [item.values arrayByAddingObjectsFromArray:appendDataSet.values];
            }
        }
    }
    return self;
}

- (HACChartDataSet *)dataSetWithLabel:(NSString *)label {
    HACChartDataSet *ret;
    for (HACChartDataSet* dataSet in self.dataSets) {
        if ([dataSet.label isEqualToString:label]) {
            ret = dataSet;
            break;
        }
    }
    return ret;
}
@end
